﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using OptusMobile.Web.ServerComponents.Common;
using OptusMobile.Web.ServerComponents.DAL;

namespace OptusMobile.Web.ServerComponents.BAL.HandsetManagement
{
    public class HandsetManager : EFManagerBase
    {
        public List<V_HandsetBasicInformation> GetAllHandsetBasicInformation()
        {
            try
            {
                return this.ObjectContext.V_HandsetBasicInformation.ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public HandsetBasicInformation GetHandsetBasicInformation(string handsetID)
        {
            try
            {
                return this.ObjectContext.HandsetBasicInformationSet.Include("HandsetBrand").FirstOrDefault(handset => handset.handsetID == handsetID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public V_HandsetInformation GetHandsetDetailInformation(string handsetID)
        {
            try
            {
                return this.ObjectContext.V_HandsetInformationSet.FirstOrDefault(handset => handset.handsetID == handsetID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public V_HandsetBasicInformation GetViewHandsetBasicInformation(string handsetID)
        {
            try
            {
                return this.ObjectContext.V_HandsetBasicInformation.FirstOrDefault(handset => handset.handsetID == handsetID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public List<V_HandsetInformation> GetAllHandsetDetailInformation()
        {
            try
            {
                return this.ObjectContext.V_HandsetInformationSet.ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public List<V_HandsetImage> GetHandsetImage()
        {
            try 
            {
                return this.ObjectContext.V_HandsetImage.ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public V_HandsetImage GetHandsetImage(string HandsetID)
        {
            try
            {
                return this.ObjectContext.V_HandsetImage.First(p => p.handsetID == HandsetID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void UpdateHandsetClickNumber(string handsetID)
        {
            try
            {
                this.ObjectContext.InsertClickRecord(handsetID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public List<V_HandsetSimilarity> GetHandsetSimilarityByAttribute()
        {
            try 
            {
                return this.ObjectContext.V_HandsetSimilarity.ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public List<HandsetImageDetail> GetHandsetDetailImage(string imageID)
        {
            List<HandsetImageDetail> ImageDetail;
            try
            {
                var result = this.ObjectContext.HandsetImageDetail.Include("HandsetImage").Where<HandsetImageDetail>(
                    p => p.HandsetImage.imageID == imageID).ToList();
                ImageDetail = result.ToList();
                return ImageDetail;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

    }
}
